package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.serivce.IEmployeeService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {

    @Autowired
    private IEmployeeService service;

    @RequestMapping("index")
    public String index() throws Exception {
        return "index";
    }
    @RequestMapping("login")
    public String login() throws Exception {
        return "redirect:/login.jsp";
    }

    //验证用户名的方法
    @RequestMapping("validate")
    @ResponseBody
    public Boolean validate(String username,Long id) throws Exception {
        Boolean aBoolean = service.selectByUsername(username,id);
        return aBoolean;
    }

    //验证用户名的方法
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Employee emp) throws Exception {
        try {
            service.saveOrUpdate(emp);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("保存失败!");
        }
    }



    @RequestMapping("convert")
    public String convert() throws Exception {
        return "convert";
    }
    @RequestMapping("change")
    public String change() throws Exception {
        return "change";
    }
}
